package org.terramagnet.workflow.dynamic.databinding.type;

import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author terrason
 */
public class LongType extends BaseDataType<Long> {

    @Override
    public String caption() {
        return "整数";
    }

    @Override
    public Long parse(String text, Long defaultValue) {
        if (!StringUtils.isNumeric(text)) {
            return defaultValue;
        }
        try {
            return Long.parseLong(text);
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }

    @Override
    public Long parse(String text) throws IllegalArgumentException {
        if (!StringUtils.isNumeric(text)) {
            throw new IllegalArgumentException(text + " 无法转换成整数");
        }
        try {
            return Long.parseLong(text);
        } catch (NumberFormatException ex) {
            throw new IllegalArgumentException(text + " 无法转换成整数", ex);
        }
    }

}
